package com.kuke.kukecommon.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.Collection;


@ApiModel("返回列表对象")
public class ResultList {

    /**
     * 总数默认-1，当为-1时说明此字段前端不需要
     */
    @ApiModelProperty(value = "总数", dataType = "String", required = true)
    private String count;
    /**
     * 返回数组
     */
    @ApiModelProperty(value = "返回数组", dataType = "Array", required = true)
    private Collection list;

    public static ResultList instance(Collection list, String count){
        ResultList listObject = new ResultList();
        if(null == list || list.size() <= 0){
            listObject.setList(new ArrayList());
        }else {
            listObject.setList(list);
        }
        if(null == count || "".equals(count) || Long.valueOf(count) <= 0){
            listObject.setCount("-1");
        }else {
            listObject.setCount(count);
        }
        return listObject;
    }

    public static ResultList instance(Collection list, Long count){
        return instance(list,count.toString()) ;
    }

    public static ResultList instance(Collection list){
        return instance(list,"-1") ;
    }

    public String getCount() {
        return count;
    }

    public void setCount(String count) {
        this.count = count;
    }

    public Collection getList() {
        return list;
    }

    public void setList(Collection list) {
        this.list = list;
    }
}
